package com.randi.system.domain.entity.sysLog;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.randi.common.annotation.Excel;
import com.randi.common.core.domain.BaseEntity;
import com.randi.common.enums.BusinessType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.annotation.Transient;

/**
 * @author ziye
 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("sys_log_operate")
@ApiModel(value = "SysLogOperate", description = "操作日志记录")
public class SysLogOperate extends BaseEntity {

    @TableId(value = "id", type = IdType.AUTO)
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "ID")
    @Excel(name = "ID")
    private Long id;

    @TableField(value = "`module_name`")
    @ApiModelProperty(value = "模块名称")
    @Excel(name = "模块名称")
    private String moduleName;

    @TableField(value = "`method_name`")
    @ApiModelProperty(value = "方法名称")
    @Excel(name = "方法名称")
    private String methodName;

    @TableField(value = "`method_path`")
    @ApiModelProperty(value = "方法路径")
    @Excel(name = "方法路径")
    private String methodPath;

    @TableField(value = "`business_type`")
    @ApiModelProperty(value = "业务类型")
    private Integer businessType;

    @TableField(value = "`request_mode`")
    @ApiModelProperty(value = "请求方式")
    @Excel(name = "请求方式")
    private String requestMode;

    @TableField(value = "`request_url`")
    @ApiModelProperty(value = "请求URL")
    @Excel(name = "请求URL")
    private String requestUrl;

    @TableField(value = "`request_ip`")
    @ApiModelProperty(value = "主机地址")
    @Excel(name = "主机地址")
    private String requestIp;

    @TableField(value = "`request_location`")
    @ApiModelProperty(value = "操作地点")
    @Excel(name = "操作地点")
    private String requestLocation;

    @TableField(value = "`request_param`")
    @ApiModelProperty(value = "请求参数")
    @Excel(name = "请求参数")
    private String requestParam;

    @TableField(value = "`respond_json`")
    @ApiModelProperty(value = "响应参数")
    @Excel(name = "响应参数")
    private String respondJson;

    @TableField(value = "`status`")
    @ApiModelProperty(value = "操作状态")
    @Excel(name = "操作状态", readConverterExp = "0=成功,1=失败")
    private Integer status;

    @TableField(value = "`error_msg`")
    @ApiModelProperty(value = "错误消息")
    @Excel(name = "错误消息")
    private String errorMsg;

    @TableField(value = "`cost_time`")
    @ApiModelProperty(value = "消耗时间")
    @Excel(name = "消耗时间")
    private Long costTime;

    @Transient
    private String operatorName;

    @Transient
    public String getKey() {
        return this.id == null ? "" : this.id.toString();
    }

    @Transient
    public String getStatusName() {
        return this.status == null || this.status == 0 ? "成功" : "失败";
    }

    @Transient
    public String getCostTimeString() {
        return this.costTime + "ms";
    }

    @Transient
    public String getBusinessName() {
        return this.businessType == null ? "" : BusinessType.values()[this.businessType].toString();
    }

}
